/**
 * Copyright © 2020 易久批信息技术有限公司. All rights reserved.
 */
package com.dysm.iterator;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author xiay
 * @since 2020/12/13 9:33 下午
 */
public class MyList {

    private static List<Object> list = new ArrayList<>();

    public void add(Object obj){
        list.add(obj);
    }

    public void remove(Object obj) {
        list.remove(obj);
    }

    public MyIterator iterator() {
        return new MyListIterator();
    }

    private class MyListIterator implements MyIterator {

        private int index;

        @Override
        public boolean hasNext() {
            return index < list.size();
        }

        @Override
        public Object getCurrent() {
            return list.get(index);
        }

        @Override
        public void next() {
            if (index < list.size()) {
                index ++;
            }
        }
    }
}
